<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset='UTF-8' />
    <title>会员中心</title>
    <meta name='keywords' content='' />
    <meta name='description' content='' />
    <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/>
    <link rel="stylesheet" href="__PUBLIC__/phone/css/gallery.css" />
    <link href="__PUBLIC__/phone/css/styles.css" rel="stylesheet" media="screen, projection" />
    <script src="__PUBLIC__/js/jquery-1.8.3.min.js"></script>
<body>
<!--公共搜索栏-->
<include file="./phone/Home/View/Public/search.html"/>
    <div class="full-screen">
        <header>
        <div class="a-bar">
            <a href="{:U('payment')}?cid={$cid}" class="a-back">
                <i class="arr left"></i>
                返回
            </a>
            <div class="a-name">
                地址管理
            </div>
            <div class="a-right">
                <a class="btn" href="{:U('addaddress')}?cid={$cid}">添加新地址</a>
            </div>
        </div>
        </header>
        <div class="address">
            <volist name="list" id="li">
                <div class="item" attr="{$li.address_id}" cid="{$cid}">
                    <p style="width:auto;">{$li.receiver}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$li.phone}</p>
                    <p>{$li.province}{$li.city}{$li.county}{$li.town}{$li.detailed_address}</p>
                    <a href="javascript:;" class="editaddress" attr="{$li.address_id}" cid="{$cid}">编辑收货地址</a>
                    <if condition="$li.status neq 1">
                        <a href="javascript:;" class="moren" attr="{$li.address_id}">设为默认</a>
                    </if>

                    <a href="javascript:;" class="address_del" attr="{$li.address_id}">删除</a>
                    <if condition="$li.status eq 1"><span>默认</span></if>
                </div>
            </volist>

        </div>
    </div>
    <div class="full-screen">
        <!--公共底部-->
        <include file="./phone/Home/View/Public/foot.html"/>
    </div>
    <div style="text-align: center;"><a target="_blank" href="http://www.miitbeian.gov.cn/">冀ICP备10201034号-2 </a></div>
</body>
<script>
    //地址删除
    $('.address_del').click(function () {
        var addr_id = $(this).attr('attr');
        var ht = $(this);
        $.ajax({
            url:"{:U('address_del')}",
            type:'post',
            data:{'addr_id':addr_id},
            success:function (e) {
                if(e == 1){
                    ht.parent().hide();
                    location.reload();
                }else if(e == -1){   //先添加再删除
                    alert('请先添加新收货地址');
                }else if(e == -2){   //默认地址不能删除
                    alert('请先更换默认地址');
                }else{
                    alert('数据异常');
                }
            }
        })
        event.stopPropagation();
    })

    //设为默认地址
    $('.moren').click(function () {
        var addr_id = $(this).attr('attr');
        $.ajax({
            url:"{:U('moren')}",
            type:'post',
            data:{'addr_id':addr_id},
            success:function (e) {
                if(e == 1){
                    location.reload();
                }else{
                    alert('数据异常');
                }
            }
        })
        event.stopPropagation();
    })

    //编辑收货地址
    $('.editaddress').click(function () {
        var addr_id = $(this).attr('attr');
        var cid = $(this).attr('cid');
         window.location.href='{:U("editaddress")}?addr_id='+addr_id+'&cid='+cid;
        event.stopPropagation();
    })

    //点击选中地址，跳转订单页
    $('.item').click(function () {
        var addr_id = $(this).attr('attr');
        var cid = $(this).attr('cid');
        window.location.href='{:U("payment")}?addr_id='+addr_id+'&cid='+cid;
    })
</script>
</html>
